<template>
  <!--模板-->
  <el-row :gutter="20" >
    <el-col :span="18">
      <el-slider v-model="formMeta.columnsNumber" :min="1" :max="7" />
      <nf-form
        v-form-drag="json"
        :model="model"
        :partModel="model2"
        v-bind="formProps"
        :childPropsList="itemMeta"
        :formMeta="formMeta"
      >
        <template v-slot:text>
          <h1>外部插槽 </h1>
          <input v-model="model.text"/>
        </template>
      </nf-form>
    </el-col>
    <el-col :span="6">
      <div
        v-for="(item, key) in model"
        :key="key"
      >
        {{key}}：<span v-if="Array.isArray(item)">【
          <div v-for="item2 in item" :key="item2">
            &nbsp; &nbsp; {{item2}}
          </div>
          】
        </span>
        <span v-else>{{item}}</span>
      </div>
    </el-col>
   
  </el-row>
  
</template>

<script lang="ts">
  import { defineComponent, reactive } from 'vue'
  import { createModel, nfForm, nfFormSlot } from '../../../../lib-elp/main'

  // 自定义指令
  import { _formDrag } from '../../../../lib-elp/main'

  import _formMeta from '../form-item/form.json'

  export default defineComponent({
    name: 'nf-elp-form-page',
    directives: {
      formDrag: _formDrag
    },
    components: {
      nfForm: nfFormSlot
    },
    props: {
    },
    setup(props, context) {

      const json = reactive(_formMeta)
      console.log('读取的 json：', json)
      const {
        formMeta,
        formProps,
        itemMeta
      } = json
      const { colOrder } = json.formMeta
      const model2 = reactive({})
      const model3 = reactive({})

      // colOrder.splice(10,100)

      // 根据 meta 创建表单的 model
      const model = createModel(itemMeta, formMeta.colOrder)
      console.log('model：', model)

      return {
        json,
        formMeta,
        formProps,
        itemMeta,
        model2,
        model3,
        model
      }
    }
  })
</script>